

#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
using namespace std;

class Solution
{
public:
    int singleNumber1(vector<int>& nums)
    {
        int res = 0;
        int n = nums.size();

        for (int i = 0, cnt = 0; i < n; ++i)
        {
            cnt = 0;
            for (int j = 0; j < n; ++j)
            {
                if (nums[i] == nums[j])
                    ++cnt;
            }

            if (1 == cnt)
            {
                res = nums[i];
                break;
            }
        }

        return res;
    }

    int singleNumber2(vector<int>& nums)
    {
        int n = nums.size();
        if (1 == n)
            return nums[0];

        sort(nums.begin(), nums.end());
        if (nums[n - 1] != nums[n - 2])
            return nums[n - 1];

        int res = 0;
        for (int i = 0; i < n; i += 3)
        {
            int flag = 0;
            for (int j = i; j + 2 < n && j < i + 2; ++j)
            {
                if (nums[j] != nums[j + 1])
                {
                    if (nums[i] == nums[i + 1])
                        res = nums[i + 2];
                    else if (nums[i] == nums[i + 2])
                        res = nums[i + 1];
                    else
                        res = nums[i];
                    flag = 1;
                    break;
                }
            }
            if (flag)
                break;
        }

        return res;
    }

    int singleNumber3(vector<int>& nums)
    {
        int res = 0;
        unordered_map<int, int> mp;

        for (const auto& e : nums)
        {
            ++mp[e];
        }

        // c++ 17
        /*for (const auto& [x, y] : mp)
        {
            if (1 == y)
            {
                res = x;
                break;
            }
        }*/
        for (auto it = mp.begin(); it != mp.end(); ++it)
        {
            if (1 == it->second)
            {
                res = it->first;
                break;
            }
        }

        return res;
    }

    int singleNumber4(vector<int>& nums)
    {
        int n = nums.size();
        if (1 == n)
            return nums[0];

        int res = 0;
        int sum = 0;

        for (int i = 0; i < 32; ++i)
        {
            sum = 0;
            for (auto e : nums)
            {
                sum += (e >> i) & 1;
            }

            res |= (sum % 3) << i;
        }

        return res;
    }
};

class LRUCache
{
    using PII = pair<int, int>;
public:
    LRUCache(int capacity)
        :_capacity(capacity)
    {
        _hash.reserve(capacity);
    }

    int get(int key)
    {
        if (_hash.find(key) != _hash.end())
        {
            auto cur = _hash[key];
            _list.splice(_list.begin(), _list, cur);

            return cur->second;
        }
        else
        {
            return -1;
        }
    }

    void put(int key, int value)
    {
        if (-1 != get(key))
        {
            _hash[key]->second = value;
        }
        else
        {
            _list.push_front({ key, value });
            _hash[key] = _list.begin();

            if (_list.size() > _capacity)
            {
                int key_del = _list.back().first;
                _list.pop_back();
                _hash.erase(key_del);
            }
        }
    }

private:
    size_t _capacity = 0;
    list<PII> _list;
    unordered_map<int, list<PII>::iterator> _hash;
};

void Test1()
{
    int* p1 = new int[5];
    int* p2 = new int(5);
    int* p3 = new int[5]{ 1, 2, 3, 4, 5 };

    for (int i = 0; i < 5; ++i)
    {
        p1[i] = i;
    }
}

int main()
{
    Test1();

	return 0;
}